<?php

declare(strict_types=1);

namespace App\Request;

use Hyperf\Validation\Request\FormRequest;

class StoreAdminRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        $id = request()->input('id',0);
        if($id){
            $rule = [
                'username' => 'required|unique:admin,username,'.$id,
                //'email' => 'required|email|unique:admin,email,'.$id,
                'password' => 'nullable|confirmed|min:6',
                //'mobile' => 'required|max:11|regex:/^1\d{10}$/|unique:admin,mobile,'.$id
            ];
        }else{
            $rule =  [
                'username' => 'required|unique:admin,username,id',
                //'email' => 'required|email|unique:admin,email,id',
                'password' => 'required|confirmed|min:6',
                //'mobile' => 'required|max:11|regex:/^1\d{10}$/|unique:admin,mobile,id'
            ];
        }
        return $rule;
    }
}
